import Vue from "vue";
import Vuex from "Vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: "",
    userName: ""
  },
  actions: {
    setToken(ctx, token) {
      ctx.commit("setToken", token);
    },
    setUserName(ctx, name) {
      ctx.commit("setUserName", name);
    }
  },
  mutations: {
    setToken(state, token) {
      localStorage.token = token;
      state.token = token;
    },
    setUserName(state, name) {
      localStorage.name = name;
      state.userName = name;
    }
  }
});
